//
//  MovieTableViewCell.m
//  Fengly_Nuo_Movie
//
//  Created by dllo on 16/1/1.
//  Copyright © 2016年 Fengly_Nuo. All rights reserved.
//

#import "MovieTableViewCell.h"
#import "MovieModel.h"
#import "UIImageView+WebCache.h"

// MARK:VIEW_CENTER_X:屏中心x轴
#define VIEW_CENTER_X self.contentView.center.x

// MARK:VIEW_CENTER_Y:屏中心y轴
#define VIEW_CENTER_Y self.contentView.center.y

// MARK:HEIGHT:屏高
#define HEIGHT self.contentView.frame.size.height

// MARK:WIDTH:屏宽
#define WIDTH self.contentView.frame.size.width

#define kMovieViewWidth _movieView.frame.size.width
#define kMovieViewHeight _movieView.frame.size.height

@interface MovieTableViewCell ()

@property (nonatomic, retain) UIView *movieView;
@property (nonatomic, retain) UIImageView *labelImage;
@property (nonatomic, retain) UILabel *nameLabel;
@property (nonatomic, retain) UIImageView *movieImage;

@end

@implementation MovieTableViewCell

- (void)setModel:(MovieModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
        
        [self assignment];
    }
}

- (void)assignment {
    _labelImage.image = [UIImage imageNamed:@"bg_eventlistcell2.png"];
    
    
    [_movieImage sd_setImageWithURL:[NSURL URLWithString:_model.image]];
    
    _nameLabel.text = _model.title;
    _nameLabel.font = [UIFont systemFontOfSize:20];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createMovieCell];
    }
    return self;
}

- (void)createMovieCell {
    self.movieView = [[UIView alloc] init];
    [self.contentView addSubview:_movieView];
    [_movieView release];
    
    self.labelImage = [[UIImageView alloc] init];
    [_movieView addSubview:_labelImage];
    [_labelImage release];
    
    self.nameLabel = [[UILabel alloc] init];
    [_movieView addSubview:_nameLabel];
    [_nameLabel release];
    
    self.movieImage = [[UIImageView alloc] init];
    [_movieView addSubview:_movieImage];
    [_movieImage release];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    _movieView.frame = CGRectMake(20, 5, WIDTH - 40, HEIGHT - 10);
    
    _labelImage.frame = CGRectMake(0, 0, WIDTH - 40, HEIGHT - 10);
    
    _movieImage.frame = CGRectMake(10, 5, kMovieViewWidth * 0.26, kMovieViewHeight - 10);
//    _movieImage.backgroundColor = [UIColor redColor];
    
    _nameLabel.frame = CGRectMake(_movieImage.frame.size.width + 30, _movieImage.center.y - 25, _movieView.frame.size.width - _movieImage.frame.size.width - 50, 50);
//    _nameLabel.backgroundColor = [UIColor lightGrayColor];
}



- (void)dealloc {
    [_model release];
    [_movieView release];
    [_labelImage release];
    [_nameLabel release];
    [_movieImage release];
    [super dealloc];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
